/*
 * @lc app=leetcode.cn id=953 lang=javascript
 *
 * [953] 验证外星语词典
 */

// @lc code=start
/**
 * @param {string[]} words
 * @param {string} order
 * @return {boolean}
 */
var isAlienSorted = function (words, order) {
  const map = {};
  order.split('').forEach((ch, index) => map[ch] = String.fromCharCode(97 + index));
  words = words.map(word => word.split('').map(ch => map[ch]).join(''));
  for (let i = 1; i < words.length; i++) {
    if (words[i] < words[i - 1]) return false;
  }
  return true;
};
// @lc code=end

// isAlienSorted(["word", "world", "row"], "worldabcefghijkmnpqstuvxyz");
